﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Trigger1 : MonoBehaviour
{
    public Transform door;
    Animator animator;
    GameObject playerObj = null;
    public GameObject cameraShowBall;

    private bool triggered = false;

    private void Awake()
    {
        animator = door.GetComponent<Animator>();
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (playerObj != null)
        {
            if (Input.GetKeyUp(KeyCode.E))
            {
                animator.SetBool("Open", true);
                triggered = true;
            }
        }

    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag.Equals("Player"))
        {
            playerObj = other.gameObject;
            if (!triggered)
            {
                cameraShowBall.GetComponent<BindShowText>().setShowText("按“E”开门");
                cameraShowBall.GetComponent<BindShowText>().showShowText();
            }
        }
    }
    private void OnTriggerExit(Collider other)
    {
        if(other.tag.Equals("Player"))
        {
            playerObj = null;
            cameraShowBall.GetComponent<BindShowText>().setShowText("");
            cameraShowBall.GetComponent<BindShowText>().showShowText();
        }
    }
}
